package com.xingongchang.baolebei.protocol;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.external.activeandroid.Model;
import com.external.activeandroid.annotation.Column;
import com.external.activeandroid.annotation.Table;
import com.insthub.BeeFramework.model.BaseModel;
@Table(name = "News")
public class News extends BaseModel{
	  @Column(name = "goodId")
	  public int goodId;
	  @Column(name = "goodName")
	  public String goodName;
	  @Column(name = "goodImg")
	  public String goodImg;
	  @Column(name = "goodThumb")
	  public String goodThumb;
	  //public ArrayList<News> children = new ArrayList<News>();
	  public static News fromJson(JSONObject jsonObject) throws JSONException {
			if (null == jsonObject) {
				return null;
			}
			News localItem = new News();
			JSONArray subItemArray;
			localItem.goodId = jsonObject.optInt("goods_id");
			localItem.goodName = jsonObject.optString("goods_name");
			localItem.goodImg= jsonObject.optString("goods_img");
			localItem.goodThumb = jsonObject.optString("goods_thumb");
//			subItemArray = jsonObject.optJSONArray("children");
//			if (null != subItemArray) {
//				for (int i = 0; i < subItemArray.length(); i++) {
//					JSONObject subItemObject = subItemArray.getJSONObject(i);
//					News subItem = News.fromJson(subItemObject);
//					localItem.children.add(subItem);
//				}
//			}
			return localItem;
		}

		public JSONObject toJson() throws JSONException {
			JSONObject localItemObject = new JSONObject();
			JSONArray itemJSONArray = new JSONArray();
			localItemObject.put("goods_id", goodId);
		    localItemObject.put("goods_name", goodName);
			localItemObject.put("goods_img", goodImg);
			localItemObject.put("goods_thumb", goodThumb);
//			for (int i = 0; i < children.size(); i++) {
//            News itemData = children.get(i);
//				JSONObject itemJSONObject = itemData.toJson();
//				itemJSONArray.put(itemJSONObject);
//			}
//			localItemObject.put("children", itemJSONArray);
			return localItemObject;
		}
}
